/**
 * 获取指定范围随机数
 * @param minimum
 * @param maximum
 * @return {Number}
*/
export function random(minimum = 0, maximum = 1) {
  return window.crypto.getRandomValues(
    new Uint32Array(1)
  )[0] / 0xffffffff * (maximum - minimum + 1) + minimum
}

/**
 * 获取UUID
 * @param number
 * @return {String}
 */
 export function uuid(size = 21): string {
  return window.crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
    byte &= 63
    if (byte < 36) {
      id += byte.toString(36)
    } else if (byte < 62) {
      id += (byte - 26).toString(36).toUpperCase()
    } else if (byte > 62) {
      id += '-'
    } else {
      id += '_'
    }
    return id
  }, '')
}
